import {
  onlineOrderDetails,
  cancelOrder,
  confirmOrder
} from '../../../../api.js'
var app = getApp(); //获取App内部的信息
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lis: [],
    nest_price:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    onlineOrderDetails({
      token: app.globalData.token,
      batchcode: options.id
    }).then(res =>{
      console.log(res)
      if (res.data.code == 666) {
        console.log(res)
        this.setData({
          lis: res.data.data.redata,
          nest_price: res.data.data.nest_price
        })
        console.log(this.data.lis)
      } else if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function () {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  setText: function(e) {
    console.log(e.currentTarget.dataset.text)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function(res) {
        wx.showToast({
          title: '复制成功',
        })
      }
    })
  },
  batchcode: function(e) {
    var num = e.currentTarget.dataset.id;
    wx.redirectTo({
      url: '/pages/payment/payment?order=' + num+'&type=3',
    })
  },
  gooter_btn_xq: function(e) {
    var batchcode = e.currentTarget.dataset.batchcode;
    cancelOrder({
      token: app.globalData.token,
      batchcode: batchcode
    }).then(res => {
      console.log(res)
      if(res.data.code == 666){
        wx.showToast({
          title: '取消订单成功',
        })
        setTimeout(function(){
          wx.redirectTo({
            url: '/pages/user/myOrder/myOrder',
          })
        },1500)
      } else if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function () {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },
  confirmOrder: function (e) {
    var batchcode = e.currentTarget.dataset.batchcode;
    confirmOrder({
      token: app.globalData.token,
      batchcode: batchcode
    }).then(res => {
      console.log(res)
      if (res.data.code == 666) {
        wx.showToast({
          title: '收货成功',
        })
        setTimeout(function () {
          wx.redirectTo({
            url: '/pages/user/myOrder/myOrder',
          })
        }, 1500)
      } else if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function () {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  }
})